using System;
using System.Collections.Generic;
using System.Text;

namespace SymAutomate
{
    /// <summary>
    /// Base for for all Parameters
    /// Error Numbers 020-029; Reference file ErrorNumbers.txt for more information.
    /// 020 Error: Unknown Parameter '%parameter name%'.
    /// </summary>
    class ParametersBase
    {
        public ParametersBase(ConsoleArguments _ConsoleArguments, List<ConsoleHelp> _ConsoleHelpList)
        {
            //check to see if unknown parameters are specified

            List<string> _KnownConsoleParameters = new List<string>();
            foreach (ConsoleHelp _ConsoleHelp in _ConsoleHelpList)
            {
                if (_ConsoleHelp.CommandName.ToLower() == _ConsoleArguments.ArgumentCollection["command"].ToString().ToLower())
                {
                    _KnownConsoleParameters = _ConsoleHelp.Parameters;
                    break;
                }
            }
            foreach (string _ConsoleArgument in _ConsoleArguments.ArgumentCollection.Keys)
            {
                bool _Found = false;
                foreach (string _LocalKnownConsoleParameter in _KnownConsoleParameters)
                {
                    if (_ConsoleArgument.ToLower() == _LocalKnownConsoleParameter.ToLower())
                    {
                        _Found = true;
                        break;
                    }
                }
                if (_Found == false)
                {
                    foreach (string _GlobalKnownConsoleParameter in SymAutomate.HostTelnetConnection.Driver.ReturnConsoleHelp().Parameters)
                    {
                        if (_ConsoleArgument.ToLower() == _GlobalKnownConsoleParameter.ToLower())
                        {
                            _Found = true;
                            break;
                        }
                    }
                }

                if (!_Found)
                {
                    throw new ReturnException("020 Error: Unknown Parameter '" + _ConsoleArgument + "'.");
                }
            }
        }
    }
}
